<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no, email=no">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="full-screen" content="yes">
    <meta name="browsermode" content="application">
    <meta name="screen-orientation" content="portrait">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>dld</title>
    <link href="/dld/home/css/sweetalert.css" rel="stylesheet">
    <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <style>
    html {
        height: 100%;
    }
    
    body {
        height: 100%;
        background: linear-gradient(rgb(204, 255, 153), rgb(204, 255, 255)) fixed;
		background-size: cover;
        overflow-x: hidden;
        font-family: SimSun;
        color: rgba(255, 255, 255, 0.8);
    }
	.fight-main p{
	margin:0;
	}
    </style>
</head>

<body id="app">
    <nav class="navbar navbar-top" style="background-color: rgb(51, 51, 51);margin-bottom: 0;">
        <div class="col-xs-3" onclick="window.location.href='MsgAction'">
            <span class="glyphicon glyphicon-home pull-left" style="font-size: 18px;margin-top: 13px;"></span>
        </div>
        <div class="col-xs-6" align="center">
            <p style=";font-size: 27px;margin: 5px 0 0 0;">dld</p>
        </div>
        <div class="col-xs-3" onclick="window.location.href='logoutUsersAction'">
            <span class="glyphicon glyphicon-off pull-right" style="font-size: 18px;margin-top: 13px;"></span>
        </div>
    </nav>
	
	<div class="fight-main">
		<p style="background-color:red;width:{{syhp_width}}%;">HP:{{syhp}}</p>
		<p class="text-center" style="background-color:rgba(0,0,0,.5);">${users.name}</p>
		<p class="text-center" style="background-color:rgba(0,0,0,.5);">${users.goodsUse[0].name}|${users.goodsUse[1].name}|${users.goodsUse[2].name}</p>
		<p class="text-center" style="background-color:rgba(0,0,0,.5);">
		<s:iterator value="users.skillUse" status="st" var="list">
			<s:property value="#list.getPossible()"/>%:<s:property value="#list.getName()"/>
		</s:iterator>
		</p>
		<p class="text-center" style="background-color:rgba(0,0,0,.5);">{{msg}}</p>

		<p style="background-color:blue;width:{{dfhp_width}}%;">HP:{{dfsyhp}}</p>
		<p class="text-center" style="background-color:rgba(0,0,0,.5);">${dfUsers.name}</p>
		<p class="text-center" style="background-color:rgba(0,0,0,.5);">${dfUsers.goodsUse[0].name}|${dfUsers.goodsUse[1].name}|${dfUsers.goodsUse[2].name}</p>
		<p class="text-center" style="background-color:rgba(0,0,0,.5);">
		<s:iterator value="dfUsers.skillUse" status="st" var="list">
			<s:property value="#list.getPossible()"/>%:<s:property value="#list.getName()"/>
		</s:iterator>
		</p>
		<p class="text-center" style="background-color:rgba(0,0,0,.5);">{{dfmsg}}</p>
		
		<button class="back btn btn-default col-xs-12" style="position:fixed;left:0;bottom:34px;height:68px;" v-on:click="randFight()">随机({{randNum}})</button>
		<button class="back btn btn-default col-xs-12" style="position:fixed;left:0;bottom:0;" v-on:click="searchFight()">放弃</button>
	</div>
	
    <script src="http://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
	<script src="/dld/home/js/jquery.tap.js"></script>
	<script src="/dld/home/js/sweetalert.min.js"></script>
	<script src="http://cdn.bootcss.com/vue/1.0.24/vue.min.js"></script>
    <script>
    	var users_id = ${users.id};
    	
    	var vue = new Vue({
    		  el: '#app',
    		  data: {
    		    ll: ${users.gameInfo.ll} <s:iterator value="users.goodsUse" status="st" var="list">+ ${users.goodsUse[st.index].ll}</s:iterator>,
    		    mj: ${users.gameInfo.mj} <s:iterator value="users.goodsUse" status="st" var="list">+ ${users.goodsUse[st.index].mj}</s:iterator>,
    		    zl: ${users.gameInfo.zl} <s:iterator value="users.goodsUse" status="st" var="list">+ ${users.goodsUse[st.index].zl}</s:iterator>,
    		    
    		    dfll: ${dfUsers.gameInfo.ll} <s:iterator value="dfUsers.goodsUse" status="st" var="list">+ ${dfUsers.goodsUse[st.index].ll}</s:iterator>,
    		    dfmj: ${dfUsers.gameInfo.mj} <s:iterator value="dfUsers.goodsUse" status="st" var="list">+ ${dfUsers.goodsUse[st.index].mj}</s:iterator>,
    		    dfzl: ${dfUsers.gameInfo.zl} <s:iterator value="dfUsers.goodsUse" status="st" var="list">+ ${dfUsers.goodsUse[st.index].zl}</s:iterator>,
    		    
    		    syhp: 0,
    		    syhp_width: 100,
    		    dfsyhp: 0,
    		    dfsyhp_width:100,
    		    randNum:0,
    		    
    		    jn: [<s:iterator value="users.skillUse" status="st" var="list">
    		    		["${users.skillUse[st.index].name}",
    		    		 "${users.skillUse[st.index].content}",
    		    		 ${users.skillUse[st.index].hurt},
    		    		 ${users.skillUse[st.index].hp},
    		    		 ${users.skillUse[st.index].ap},
    		    		 ${users.skillUse[st.index].ad},
    		    		 ${users.skillUse[st.index].hj},
    		    		 ${users.skillUse[st.index].ll},
    		    		 ${users.skillUse[st.index].mj},
    		    		 ${users.skillUse[st.index].zl},
    		    		 ${users.skillUse[st.index].possible},
    		    		 ],
    		    		 </s:iterator>],
    		    dfjn: [<s:iterator value="dfUsers.skillUse" status="st" var="list">
			    		["${dfUsers.skillUse[st.index].name}",
			    		 "${dfUsers.skillUse[st.index].content}",
			    		 ${dfUsers.skillUse[st.index].hurt},
			    		 ${dfUsers.skillUse[st.index].hp},
			    		 ${dfUsers.skillUse[st.index].ap},
			    		 ${dfUsers.skillUse[st.index].ad},
			    		 ${dfUsers.skillUse[st.index].hj},
			    		 ${dfUsers.skillUse[st.index].ll},
			    		 ${dfUsers.skillUse[st.index].mj},
			    		 ${dfUsers.skillUse[st.index].zl},
			    		 ${dfUsers.skillUse[st.index].possible},
			    		 ],
			    		 </s:iterator>],
			    msg:"",
			    dfmsg:"",
    		  },
    		  computed: {
    			  hp: function(){
    				  return ${users.gameInfo.hp} + 50 + this.ll * 5 <s:iterator value="users.goodsUse" status="st" var="list">+ ${users.goodsUse[st.index].hp}</s:iterator>;
    			  },
    			  ap: function(){
    				  return this.zl <s:iterator value="users.goodsUse" status="st" var="list">+ ${users.goodsUse[st.index].ap}</s:iterator>;
    			  },
    			  ad: function(){
    				  return this.ll * 0.5 <s:iterator value="users.goodsUse" status="st" var="list">+ ${users.goodsUse[st.index].ad}</s:iterator>;
    			  },
    			  hj: function(){
    				  return this.mj * 0.2 <s:iterator value="users.goodsUse" status="st" var="list">+ ${users.goodsUse[st.index].hj}</s:iterator>;
    			  },
    			  dfhp: function(){
    				  return ${dfUsers.gameInfo.hp} + 50 + this.dfll * 5 <s:iterator value="dfUsers.goodsUse" status="st" var="list">+ ${dfUsers.goodsUse[st.index].hp}</s:iterator>;
    			  },
    			  dfap: function(){
    				  return this.dfzl <s:iterator value="dfUsers.goodsUse" status="st" var="list">+ ${dfUsers.goodsUse[st.index].ap}</s:iterator>;
    			  },
    			  dfad: function(){
    				  return this.dfll * 0.5 <s:iterator value="dfUsers.goodsUse" status="st" var="list">+ ${dfUsers.goodsUse[st.index].ad}</s:iterator>;
    			  },
    			  dfhj: function(){
    				  return this.dfmj * 0.2 <s:iterator value="dfUsers.goodsUse" status="st" var="list">+ ${dfUsers.goodsUse[st.index].hj}</s:iterator>;
    			  },
    		  },
    		  methods:{
    			  randFight: function(){
    				  if(this.jn.length != 0){
	    				  this.randNum = Math.floor(Math.random()*100+1);
	    				  var i = -1;
	    				  var jn_num = this.randNum;
	    				  do{
	    					  i++;
	    					  jn_num = jn_num - this.jn[i][10];
	    				  }while(jn_num > 0 && this.jn.length-1 != i)
	    					  
	    				  if(jn_num <= 0){
		    				  var hurt = this.jn[i][2]
		    				  + this.jn[i][3] * this.hp
		    				  + this.jn[i][4] * this.ap
		    				  + this.jn[i][5] * this.ad
		    				  + this.jn[i][6] * this.hj
		    				  + this.jn[i][7] * this.ll
		    				  + this.jn[i][8] * this.mj
		    				  + this.jn[i][9] * this.zl;
		    				  console.log(hurt);
		    				  hurt = hurt * (1 - (0.06*this.dfhj/1+0.06*this.dfhj));
		    				  this.dfsyhp = this.dfsyhp - hurt;
		    				  this.msg = "使用技能：" + this.jn[i][0] + " 伤害：" + hurt;
	    				  }else{
	    					  this.msg = "本回合无操作";
	    				  }
    				  }else{
    					  this.msg = "本回合无操作";
    				  }
    				  
    				  if(this.dfjn.length != 0){
	    				  dfrandNum = Math.floor(Math.random()*100+1);
	    				  var i = -1;
	    				  var dfjn_num = dfrandNum;
	    				  do{
	    					  i++;
	    					  dfjn_num = dfjn_num - this.dfjn[i][10];
	    				  }while(dfjn_num > 0 && this.dfjn.length-1 != i)
	    					  
	    				  if(dfjn_num <= 0){
		    				  var hurt = this.dfjn[i][2]
		    				  + this.dfjn[i][3] * this.dfhp
		    				  + this.dfjn[i][4] * this.dfap
		    				  + this.dfjn[i][5] * this.dfad
		    				  + this.dfjn[i][6] * this.dfhj
		    				  + this.dfjn[i][7] * this.dfll
		    				  + this.dfjn[i][8] * this.dfmj
		    				  + this.dfjn[i][9] * this.dfzl;
		    				  console.log(hurt);
		    				  hurt = hurt * (1 - (0.06*this.hj/1+0.06*this.hj));
		    				  this.syhp = this.syhp - hurt;
		    				  this.dfmsg = "使用技能：" + this.dfjn[i][0] + " 伤害：" + hurt;
	    				  }else{
	    					  this.dfmsg = "本回合无操作";
	    				  }
    				  }else{
    					  this.dfmsg = "本回合无操作";
    				  }
    				  this.ifEnd();
    			  },
    			  ifEnd: function(){
    				  var win_users = "";
    				  console.log('asdas');
    				  if(this.syhp <= 0){
    					  win_users = "dfUsers";
    				  }
    				  if(this.dfsyhp <= 0){
    					  win_users = "self";
    				  }
    				  if(win_users != ""){
     	        			var num = Math.floor(Math.random()*100+1);
       	        			if(num <= 3){
       	        	            $.ajax({
       	        	                type: 'POST',
       	        	                url: "UsersIfEndAction",
       	        	                data:{
       	        	                	win_users: win_users,
       	        	                	get_type: "Goods"
       	        	                },
       	        	                cache: false,
       	        	                async: true,
       	        	                secureuri:false,
       	        	                success: function(data) {
       	        	                	if(win_users == "self"){
       	        	                		swal("你赢了,获得对方物品随机!" + data.result);
       	        	                	}else{
       	        	                		swal("你输了,失去物品随机!" + data.result);
       	        	                	}
       	        	                	setTimeout(function(){
       		    		    			    window.location.href="usersAction";
       		                            }, 2000);
       	        	                },
       	        	                error: function() {
       	        	                }
       	        	            });
       	        			}else if(num <= 8){
       	        	            $.ajax({
       	        	                type: 'POST',
       	        	                url: "UsersIfEndAction",
       	        	                data:{
       	        	                	win_users: win_users,
       	        	                	get_type: "Skill"
       	        	                },
       	        	                cache: false,
       	        	                async: true,
       	        	                secureuri:false,
       	        	                success: function(data) {
       	        	                	if(win_users == "self"){
       	        	                		swal("你赢了,获得对方技能随机!" + data.result);
       	        	                	}else{
       	        	                		swal("你输了,失去技能随机!" + data.result);
       	        	                	}
       	        	                	setTimeout(function(){
       		    		    			    window.location.href="usersAction";
       		                            }, 2000);
       	        	                },
       	        	                error: function() {
       	        	                }
       	        	            });
       	        			}else if(num <= 13){
       	        	            $.ajax({
       	        	                type: 'POST',
       	        	                url: "UsersIfEndAction",
       	        	                data:{
       	        	                	win_users: "self",
       	        	                	get_type: "prop"
       	        	                },
       	        	                cache: false,
       	        	                async: true,
       	        	                secureuri:false,
       	        	                success: function(data) {
       	        	                	if(win_users == "self"){
       	        	                		swal("你赢了,获得对方属性随机!" + data.result + "个属性点");
       	        	                	}else{
       	        	                		swal("你输了,失去属性随机!" + data.result + "个属性点");
       	        	                	}
       	        	                	setTimeout(function(){
       		    		    			    window.location.href="usersAction";
       		                            }, 2000);
       	        	                },
       	        	                error: function() {
       	        	                }
       	        	            });
       	        			}else{
	        	                if(win_users == "self"){
   	        	                	swal("你赢了,啥都没!");
   	        	                }else{
   	        	                	swal("你输了,啥都没!");
   	        	                }
	       		    			setTimeout(function(){
	    		    			    window.location.href="usersAction";
	                            }, 2000);
       	        			}
    				  }
    			  }
    		  },
    		  ready: function(){
      		      this.syhp = this.hp;
    		      this.dfsyhp = this.dfhp;
    		  }
    		});
    </script>
</body>

</html>
